<template>
	<view>
		<!-- 用户信息表单 -->
		<uni-forms :modelValue="user">
			<uni-forms-item label="用户名" name="username">
				<uni-easyinput type="text" v-model="user.username" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="password">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码" />
			</uni-forms-item>
			<uni-forms-item label="手机号" name="phone">
				<uni-easyinput type="text" v-model="user.phone" placeholder="请输入手机号" />
			</uni-forms-item>
			<uni-forms-item label="收货地址" name="address">
				<uni-easyinput type="text" v-model="user.address" placeholder="请输入收货地址" />
			</uni-forms-item>

			<button :plain="false" @click="reg()">注册</button>
			<button :plain="false" @click="back()">返回</button>
			<text>{{msg}}</text>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: '',
					password: '',
					address: '',
					phone: '',
				},
				msg: '',
			}
		},
		methods: {
			back() {
				uni.navigateBack({

				})
			},
			reg() { //注册
				uni.request({
					url: 'http://localhost:8081/user/insertOneUser',
					method: 'POST',
					data: this.user,
					success: (res) => {
						if (!res.data.result) {
							this.msg = "用户已存在";
						} else {
							uni.navigateTo({
								url: 'login',
							})
						}
					},
				})
			}
		}
	}
</script>

<style>

</style>
